import request from '@/utils/request'
import type { ApiResponse } from './components/ApiResponse'
import type { CartListType, mergeCartType, AddCartType } from './components/cartType'

// 获取购物车列表
export const getCartListApi = () => {
  return request.get<ApiResponse<[CartListType]>>('/member/cart')
}

// 合并购物车-登录后需要把本地购物车合并，且清空本地购物车
export const mergeCartApi = (data: mergeCartType[]) => {
  return request.post<ApiResponse<null>>('/member/cart/merge', data)
}

// 加入购物车
export const addCartApi = (data: AddCartType) => {
  return request.post<ApiResponse<CartListType>>('/member/cart', data)
}

// 删除购物车
export const deleteCartApi = (ids: string[]) => {
  return request.delete<ApiResponse<null>>('/member/cart', {
    data: { ids },
  })
}
